package com.wf.day_0614.test2;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author mpk
 * @since 2024/6/14 17:59:47
 */
/*
4.有三个线程 分别打印A B C 要求有序打印 并且循环10次 count=1 2 3 4 5 6 ==> 使用AtomicInteger实现*/
public class Demo {
    public static void main(String[] args) {


        AtomicInteger count = new AtomicInteger(0);

        Thread a = new Thread(
                () ->
                {
                    while (count.get() < 30) {
                        if (count.get() % 3 == 0 && count.get()<30) {
                            System.out.print("A");
                            count.incrementAndGet();
                        }
                    }

                }
        );
        Thread b = new Thread(
                () ->
                {
                    while (count.get() < 30) {
                        if (count.get() % 3 == 1) {
                            System.out.print("B");
                            count.incrementAndGet();
                        }
                    }

                }
        );
        Thread c = new Thread(
                () ->
                {
                    while (count.get() < 30) {
                        if (count.get() % 3 == 2) {
                            System.out.println("C");
                            count.incrementAndGet();

                        }
                    }

                }
        );


        a.start();
        b.start();
        c.start();


    }


}
